package com.stockz.equity.charting.display.indicator;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.model.Line;
import com.stockz.equity.charting.model.Point;
import com.stockz.equity.charting.painter.indicator.SupportResistenceIndicatorPainter;
import com.stockz.equity.charting.util.Constant.OVERLAY;
import com.stockz.equity.indicator.Indicator;
import com.stockz.equity.indicator.supportResistence.SupportResistenceIndicator;
import com.stockz.equity.indicator.supportResistence.SupportResistenceIndicatorConfiguration;
import com.stockz.equity.model.Bar;

@Component
public class SupportResistenceDisplayableIndicatorConfiguration extends
		AbstractDisplayableIndicatorConfiguration {

	@Autowired
	private SupportResistenceIndicator supportResistenceIndicator;
	
	private List<Line> lineList = new ArrayList<Line>();
	
	@Override
	public double[] getValues() {
		return new double[0];
	}
	
	public List<Line> getLines(){
		return lineList;
	}
	
	@Override
	public void refreshValues() {
		List<Bar> barList = getStockChartView().getSelectedStockChart()
		.getStockChartPanel().getStockChartPanelState()
		.getBarList();
		List<Bar> extreams = supportResistenceIndicator.getExtreams(barList);
		getStockChartView().getSelectedStockChart()
		.getStockChartPanel().getStockChartPanelState().getShapeSet().removeAll(lineList);
		lineList.clear();
		for(Bar bar : extreams){
			lineList.add(new Line(new Point(bar.getValue(getBarValueType()),barList.indexOf(bar)),
				 	new Point(bar.getValue(getBarValueType()),Integer.MAX_VALUE)));
		}
	}
	
	@Override
	public Class<SupportResistenceIndicatorPainter> getPainterClass() {
		return SupportResistenceIndicatorPainter.class;
	}
	
	@Override
	public Indicator<SupportResistenceIndicatorConfiguration> getIndicator() {
		return supportResistenceIndicator;
	}

	@Override
	public String getDescription() {
		return getShortName()+", "+supportResistenceIndicator.getIndicatorConfiguration().getPercentage();
	}

	@Override
	public String getFullName() {
		return "Support/Resistence";
	}

	@Override
	public OVERLAY getOverlay() {
		return OVERLAY.PRICE;
	}

	@Override
	public String getShortName() {
		return "S&R";
	}

	@Override
	public boolean isOverlappable() {
		return true;
	}
}
